import {
  Body,
  Controller,
  Delete,
  Get,
  HttpStatus,
  Param,
  Post,
  Put,
  Query,
} from '@nestjs/common';
import { InformService } from './inform.service';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { PublicVoError, PublicVoSuccess } from 'src/utils/publicVo';
import { CreateInformDto } from './dto/create-inform-dto';
import { UpdateInformDto } from './dto/update-inform-dto';
import { InformListVo } from './vo/list-inform-vo';
import { RequireLogin } from 'src/middleware/auth/custom.decorator';

@ApiTags('消息中心')
@Controller('inform')
export class InformController {
  constructor(private readonly informService: InformService) {}

  @Post()
  @ApiBearerAuth()
  @RequireLogin()
  @ApiOperation({ summary: '消息新增', description: '消息新增接口' })
  @ApiResponse({
    status: HttpStatus.OK,
    description: '请求成功',
    type: PublicVoSuccess,
  })
  @ApiResponse({
    status: HttpStatus.BAD_REQUEST,
    description: '请求失败',
    type: PublicVoError,
  })
  async create(@Body() createInformDto: CreateInformDto) {
    return await this.informService.create(createInformDto);
  }

  @Delete(':id')
  @ApiBearerAuth()
  @RequireLogin()
  @ApiOperation({ summary: '消息删除', description: '消息删除接口' })
  @ApiResponse({
    status: HttpStatus.OK,
    description: '请求成功',
    type: PublicVoSuccess,
  })
  @ApiResponse({
    status: HttpStatus.BAD_REQUEST,
    description: '请求失败',
    type: PublicVoError,
  })
  async remove(@Param('id') id: string) {
    return await this.informService.remove(+id);
  }

  @Put()
  @ApiBearerAuth()
  @RequireLogin()
  @ApiOperation({ summary: '消息修改', description: '消息修改接口' })
  @ApiResponse({
    status: HttpStatus.OK,
    description: '请求成功',
    type: PublicVoSuccess,
  })
  @ApiResponse({
    status: HttpStatus.BAD_REQUEST,
    description: '请求失败',
    type: PublicVoError,
  })
  async update(@Body() updateInformDto: UpdateInformDto) {
    return await this.informService.update(updateInformDto);
  }

  @Get()
  @ApiBearerAuth()
  @RequireLogin()
  @ApiOperation({ summary: '消息列表', description: '消息列表接口' })
  @ApiResponse({
    status: HttpStatus.OK,
    description: '请求成功',
    type: InformListVo,
  })
  @ApiResponse({
    status: HttpStatus.BAD_REQUEST,
    description: '请求失败',
    type: PublicVoError,
  })
  @ApiQuery({
    name: 'pageNum',
    type: String,
    description: '页码',
    required: true,
  })
  @ApiQuery({
    name: 'pageSize',
    type: String,
    description: '页数',
    required: true,
  })
  @ApiQuery({
    name: 'content',
    type: String,
    description: '消息内容',
    required: false,
  })
  @ApiQuery({
    name: 'type',
    type: String,
    description: '消息类型',
    required: false,
  })
  @ApiQuery({
    name: 'status',
    type: String,
    description: '消息状态',
    required: false,
  })
  async list(
    @Query('pageNum') pageNum: number,
    @Query('pageSize') pageSize: number,
    @Query('content') content: string,
    @Query('type') type: string,
    @Query('status') status: string,
  ) {
    return await this.informService.list(
      pageNum,
      pageSize,
      content,
      type,
      status,
    );
  }
}
